<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('人员列表')" />
	<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								人员ID：<input type="text" name="personId"/>
							</li>
							<li>
								姓名：<input type="text" name="personName"/>
							</li>
							<li>
								性别：<select name="sex" th:with="type=${@dict.getType('sys_user_sex')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>

							<li>
								所属组织：<input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择所属组织">
								<input type="hidden" id="deptId" name="deptId"/>
							</li>

							<li class="select-time new">
								<label class="font-noraml">创建时间：</label>
								<div class="input-daterange input-group">
									<input type="text" class="input-sm form-control" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
									<span>-</span>
									<input type="text" class="input-sm form-control" id="endTime" placeholder="结束时间"  name="params[endTime]"/>
								</div>
							</li>
							<li>
								绑定状态：<select name="isBind" th:with="type=${@dict.getType('sys_bind_status')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li style="float: right">
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.addPerson()" shiro:hasPermission="system:person:add">
					<i class="fa fa-plus"></i> 添加
				</a>
<!--				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.editPerson()" shiro:hasPermission="system:person:edit">-->
<!--					<i class="fa fa-edit"></i> 修改-->
<!--				</a>-->
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeIsBindAll()" shiro:hasPermission="system:person:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="system:person:import">
					<i class="fa fa-upload"></i> 导入
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:person:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
	 <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:person:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:person:remove')}]];
        var prefix = ctx + "system/person";
		var types = [[${@dict.getType('sys_user_sex')}]];

        $(function() {
			$('input:not([autocomplete]),textarea:not([autocomplete]),select:not([autocomplete])').attr('autocomplete', 'off');
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				importUrl: prefix + "/importData",
				importTemplateUrl: prefix + "/importTemplate",
                modalName: "人员",
		        showExport: false,
				uniqueId:"personId",
                columns: [{
		            checkbox: true
		        },
				{
					title: "序号",
					formatter: function (value, row, index) {
						return $.table.serialNumber(index);
					}
				},
				{
					field : 'personId', 
					title : '人员ID',
					sortable: true,
					visible: true,
					formatter: function(value, row, index) {
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'personName', 
					title : '姓名',
					sortable: true,
					formatter: function(value, row, index) {
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'sex', 
					title : '性别',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(types, value);
					}
				},
				{
					field : 'certificateType',
					title : '证件类型',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'certificateNumber', 
					title : '证件号码',
					sortable: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'deptName',
					title : '所属组织',
					sortable: true,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'address',
					title : '家庭地址',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'tel',
					title : '电话',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'linkmanName',
					title : '紧急联系人',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'linkmanTel',
					title : '紧急联系人电话',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
					{
						field : 'tagId',
						title : '标签ID',
						sortable: false,
						visible: true,
						formatter: function(value, row, index) {
							value = $.common.nullToStr(value);
							var html ="<span style='white-space:nowrap'>"+value+"</span>"
							return html;
						}
					},
				{
					field : 'createBy',
					title : '创建者',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'createTime', 
					title : '登记时间',
					sortable: true,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'updateBy',
					title : '更新者',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'updateTime',
					title : '更新时间',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var html ="<span style='white-space:nowrap'>"+value+"</span>"
						return html;
					}
				},
				{
					field : 'remark',
					title : '备注',
					sortable: false,
					visible: false,
					formatter: function(value, row, index) {
						value = $.common.nullToStr(value);
						var tooltip = $.table.tooltip(value);
						var html ="<span style='white-space:nowrap'>"+tooltip+"</span>"
						return html;
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						actions.push('<span style=\'white-space:nowrap\'>');
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.editPerson(\'' + row.personId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="#" onclick="locationAlarm(\'' + row.personId + '\')"><i class="fa fa-play-circle-o"></i>定位</a> ');
						actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="#" onclick="openTagInfo(\'' + row.tagId + '\')"><i class="fa fa-camera-retro"></i>标签</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.removeIsBind(\'' + row.personId + '\')"><i class="fa fa-remove"></i>删除</a>');
						actions.push('</span>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
			$("#startTime").datetimepicker({
				format: "yyyy-mm-dd hh:ii:ss",
				autoclose: true
			});
			$("#endTime").datetimepicker({
				format: "yyyy-mm-dd hh:ii:ss",
				autoclose: true
			});
        });
		/*人员管理-新增-选择部门树*/
		function selectDeptTree() {
			var treeId = $("#treeId").val();
			var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
			var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择组织',
				width: "380",
				url: ctx + "system/dept/selectDeptTree/" + deptId,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}

		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
				$("#treeId").val(body.find('#treeId').val());
				$("#treeName").val(body.find('#treeName').val());
				$("#deptId").val(body.find('#treeId').val());
				layer.close(index);
			}
		}
		<!-- laydate示例 -->
		layui.use('laydate', function(){
			var laydate = layui.laydate;
			laydate.render({
				elem: '#startTime',
				type: 'datetime'
			});
			laydate.render({
				elem: '#endTime',
				type: 'datetime'
			});
		});
		function locationAlarm(personId) {
			//通过personID获取标签Id
			$.ajax({
				url:prefix+"/getTagIdByPersonId?personId="+personId,
				type: 'post',
				data: "",
				dataType:"json",
				async:false,
				// processData: false,
				// contentType: false,
				success: function(result) {
					var tagId = result.msg;
					if (tagId!=null && tagId!=""){
						$.modal.openTab("定位" + $.table._option.modalName,"/mapIndex/"+tagId);
					} else {
						$.modal.alertWarning("未绑定标签，无法定位");
					}
				},
				error : function(request) {
					$.modal.alertError("系统错误");
				},
			});

		}
		function openTagInfo(tagId) {
			if (tagId==""||tagId==null||tagId=="null"){
				$.modal.alertWarning("未绑定标签");
			}else {
				$.modal.openTab("标签信息","/system/lable/"+tagId);
			}
		}
    </script>
</body>
<form id="importForm" enctype="multipart/form-data" class="mt20 mb10" style="display: none;">
	<div class="col-xs-offset-1">
		<input type="file" id="file" name="file"/>
		<div class="mt10 pt5">
<!--			<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的人员数据-->
			&nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
		</div>
		<font color="red" class="pull-left mt10">
			提示：仅允许导入“xls”或“xlsx”格式文件！
		</font>
	</div>
</form>
</html>